package com.onethinker.service.impl;

import com.onethinker.common.constants.ProjectConstant;
import com.onethinker.service.UploadPicService;
import com.onethinker.service.impl.AlibabaCloudSavePicImpl;
import com.onethinker.service.impl.LocalStorageSavePicImpl;
import com.onethinker.service.impl.TencentCloudSavePicImpl;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

/**
 * @Author: yangyouqi
 * @Date: 2022/4/2 15:29
 * @Description: 图片工厂处理集合
 */
@Component
public class UploadPicFactory {

    @Resource
    private AlibabaCloudSavePicImpl alibabaCloudSavePic;

    @Resource
    private LocalStorageSavePicImpl localStorageSavePic;

    @Resource
    private TencentCloudSavePicImpl tencentCloudSavePic;

    /**
     * 获取具体上传来源
     * @param uploadType
     * @return
     */
    public UploadPicService getUploadPicService(String uploadType) {

        if (ObjectUtils.isEmpty(uploadType)) {
            // 如果不选择则默认本地上传
            return localStorageSavePic;
        }

        // 本地存储
        if (uploadType.equalsIgnoreCase(ProjectConstant.PIC_SAVE_LOCALHOST)) {
            return localStorageSavePic;
        }
        // 腾讯云存储
        if (uploadType.equalsIgnoreCase(ProjectConstant.PIC_SAVE_TENCENT_COS)) {
            return tencentCloudSavePic;
        }
        // 阿里云对象存储
        if (uploadType.equalsIgnoreCase(ProjectConstant.PIC_SAVE_ALIYUM_OSS)) {
            return alibabaCloudSavePic;
        }

        // 匹配不到有效存储方式则默认使用本地上传
        return localStorageSavePic;
    }
}
